package com.myebills.ebpsfrontend.cust.maxis;

import com.myebills.ebpsfrontend.cust.controller.*;
import com.checkfree.isolutions.admin.ObjectId;
import com.checkfree.isolutions.statement.persist.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class CusStmtMesgServlet_v1r00 extends EbppxTransactionServlet {

    /**
     *
     *
     */
    public void doTransaction(HttpServletRequest req, HttpServletResponse res)
    throws ServletException {
        try {
            final HttpSession session = req.getSession(false);
            if (null == session) {
                throw new ServletException("Session must be already established");
            }

    		final String randomKey = (String) session.getAttribute(EbppxConstants.RANDOM_KEY);

            final EbppxUrlManager urlManager = getUrlManager(req);

            final String encryptedStmtId = urlManager.getSecureParameter(EbppxConstants.STATEMENT_ID);
            final String sOidStatement = EncryptionHelper.decrypt(encryptedStmtId,randomKey);
            if (sOidStatement.length() == 0) {
                throw new ServletException("Missing statement identifier");
            }

            final Statement cfiStatement = getStatementHome().findById(new ObjectId(sOidStatement));

            req.setAttribute(EbppxConstants.CFI_STATEMENT, cfiStatement);

            forwardToMappedUrl(req, res, EbppxConstants.URL_JSP_PARAM);
        } catch (ServletException e) {
            // Just re-throw these
            throw e;
        } catch (Throwable t) {
            throw new ServletException(t.toString(), t);
        }
    }
}